package com.pstreets.lwuit.demo.widgets;

import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.TextField;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.impl.midp.VKBImplementationFactory;
import com.sun.lwuit.impl.midp.VirtualKeyboard;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import javax.microedition.midlet.MIDlet;

/**
 * @author james
 */
public class VirtualKeyboardDemo extends MIDlet {

    public void startApp() {

        VKBImplementationFactory.init();

        //init the LWUIT display
        Display.init(this);

        //setting the application theme
        try {
            Resources r = Resources.open("/LWUITtheme.res");
            UIManager.getInstance().setThemeProps(r.getTheme(r.getThemeResourceNames()[0]));
        } catch (Exception e) {
        }


        Form mainForm = new Form("TextField  Demo");

        mainForm.setLayout(new BorderLayout());

        TextField textfield = new TextField();
        String[][] SEARCH_QWERTY = new String[][]{
            {"q", "w", "e", "r", "t", "y", "u", "i", "o", "p"},
            {"a", "s", "d", "f", "g", "h", "j", "k", "l"},
            {"$Shift$", "z", "x", "c", "v", "b", "n", "m", "$Delete$"},
            {"$Mode$", "$Space$", "$Search$"}
        };
        VirtualKeyboard vkb = new VirtualKeyboard();
         //add the new input mode
        vkb.addInputMode("ABC_S", SEARCH_QWERTY);
        vkb.setInputModeOrder(new String[]{"ABC_S"});
       //add the new special button to the vkb
        vkb.addSpecialButton("Search", new Command("Search") {

            public void actionPerformed(ActionEvent evt) {
         //search logic...
            }
        });

        VirtualKeyboard.bindVirtualKeyboard(textfield, vkb);


        mainForm.addComponent(BorderLayout.CENTER, textfield);

        mainForm.setTransitionOutAnimator(CommonTransitions.createFade(400));

        mainForm.addCommand(new Command("Left soft key", 2));
        mainForm.addCommand(new Command("Right Soft key", 2));

        mainForm.show();


    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
}
